package thread.java20230113;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 1000个线程对日期进行初始化
 */
public class Demo59 {
    static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("mm:ss");

    public static void main(String[] args) {
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        for (int i = 0; i < 1000; i++) {
            int finalI = i;
            Runnable runnable = ()->{
                Date date = new Date(finalI * 1000);//2s
                System.out.println(dateFormat(date));
            };
            executorService.execute(runnable);
        }

    }

    private static String dateFormat(Date date) {
        String result;
        synchronized (simpleDateFormat){
            result = simpleDateFormat.format(date);
        }
        return result;
    }
}
